<template>
  <div class="playlists-container">
    <div class="outter">
      <div class="inner">
        <div class="top-card">
          <div class="icon-wrap">
            <img :src="highQuality.coverImgUrl" alt />
          </div>
          <div class="content-wrap">
            <div class="tag" @click="golist(highQuality.id)">精品歌单</div>
            <div class="title">{{ highQuality.name }}</div>
            <div class="info">{{ highQuality.description }}</div>
          </div>
          <img :src="highQuality.coverImgUrl" alt class="bg" />
          <div class="bg-mask"></div>
        </div>
        <div class="tab-container">
          <!-- tab栏 顶部 -->
          <div class="tab-bar">
            <span
              class="item"
              :class="{ active: tag === '全部' }"
              @click="tag = '全部'"
              >全部</span
            >
            <span
              class="item"
              :class="{ active: tag === '欧美' }"
              @click="tag = '欧美'"
              >欧美</span
            >
            <span
              class="item"
              :class="{ active: tag === '华语' }"
              @click="tag = '华语'"
              >华语</span
            >
            <span
              class="item"
              :class="{ active: tag === '流行' }"
              @click="tag = '流行'"
              >流行</span
            >
            <span
              class="item"
              :class="{ active: tag === '说唱' }"
              @click="tag = '说唱'"
              >说唱</span
            >
            <span
              class="item"
              :class="{ active: tag === '摇滚' }"
              @click="tag = '摇滚'"
              >摇滚</span
            >
            <span
              class="item"
              :class="{ active: tag === '民谣' }"
              @click="tag = '民谣'"
              >民谣</span
            >
            <span
              class="item"
              :class="{ active: tag === '电子' }"
              @click="tag = '电子'"
              >电子</span
            >
            <span
              class="item"
              :class="{ active: tag === '轻音乐' }"
              @click="tag = '轻音乐'"
              >轻音乐</span
            >
            <span
              class="item"
              :class="{ active: tag === '影视原声' }"
              @click="tag = '影视原声'"
              >影视原声</span
            >
            <span
              class="item"
              :class="{ active: tag === 'ACG' }"
              @click="tag = 'ACG'"
              >ACG</span
            >
            <span
              class="item"
              :class="{ active: tag === '怀旧' }"
              @click="tag = '怀旧'"
              >怀旧</span
            >
            <span
              class="item"
              :class="{ active: tag === '治愈' }"
              @click="tag = '治愈'"
              >治愈</span
            >
            <!-- <span
                class="item"
                :class="{ active: tag === '旅行' }"
                @click="tag = '旅行'"
                >旅行</span
              > -->
          </div>
          <!-- tab的内容区域 -->
          <div class="recommended">
            <div class="recombox">
              <div
                class="recom-item"
                v-for="(item, index) in palyLists"
                :key="index"
              >
                <div class="imgbox" @click="golist(item.id)">
                  <div class="dsc">
                    <i>播放量：{{ item.subscribedCount | count }}</i>
                  </div>
                  <img :src="item.coverImgUrl + '?param=200y200'" alt />
                </div>
                <p>{{ item.name }}</p>
              </div>
            </div>
          </div>
        </div>
        <!-- 分页器 -->
        <div class="pagebox">
          <el-pagination
            @current-change="handleCurrentChange"
            background
            layout="prev, pager, next"
            :total="total"
            :current-page="page"
            :page-size="limit"
          ></el-pagination>
        </div>
        <div class="more" @click="more">
          查看更多
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { GetHightQuality, GetList } from "../../../../api/music"
export default {
  name: "recommend",
  data() {
    return {
      highQuality: {},
      tag: "全部",
      palyLists: [],
      // 总条数
      total: 0,
      limit: 12,
      // 页码
      page: 1,
    }
  },
  created() {
    this.gethightquality()
    this.getList()
  },
  filters: {
    count(playcount) {
      if (playcount > 10000) {
        playcount = Math.ceil(playcount / 10000) + "万"
      }
      return playcount
    },
  },
  watch: {
    tag(newVal, oldVal) {
      this.page = 1
      this.tag = newVal
      this.gethightquality()
      this.getList()
    },
  },
  methods: {
    golist(id) {
      this.$router.push(`/home/index/details?id=${id}`)
    },
    handleCurrentChange(val) {
      this.page = val
      this.getList()
      this.$EventBus.$emit("scrollTo", 0)
    },
    async gethightquality() {
      const res = await GetHightQuality({
        cat: this.tag,
      })
      this.highQuality = res.playlists[0]
    },
    async getList() {
      const res = await GetList({
        offset: (this.page - 1) * this.limit,
        cat: this.tag,
        limit: 20,
      })
      this.palyLists = res.playlists
      this.total = res.total
    },
    // 移动端加载更多
    async more() {
      const res = await GetList({
        offset: (this.page - 1) * this.limit,
        cat: this.tag,
        limit: 12,
      })
      this.palyLists.push(...res.playlists)
      this.total = res.total
    },
  },
}
</script>

<style lang="scss" scoped>
@import "../../../../../static/scss/common.scss";

.playlists-container {
  width: 100%;
  overflow: hidden;
  box-sizing: border-box;
}
.playlists-container .top-card {
  margin: 20px 20px;
  padding: 20px;
  display: flex;
  position: relative;
  overflow: hidden;
  border-radius: 5px;
}

.playlists-container .top-card .icon-wrap {
  margin-right: 20px;
  z-index: 1;
}

.playlists-container .top-card .icon-wrap img {
  width: 160px;
  height: 160px;
}

.playlists-container .top-card .content-wrap {
  z-index: 1;
}

.playlists-container .top-card .content-wrap .tag {
  color: #dfac67;
  border: 1px solid #dfac67;
  width: 100px;
  height: 30px;
  text-align: center;
  border-radius: 5px;
  font-size: 16px;
  line-height: 30px;
  cursor: pointer;
}

.playlists-container .top-card .content-wrap .title {
  color: white;
  padding-top: 10px;
}

.playlists-container .top-card .content-wrap .info {
  color: #888482;
  line-height: 20px;
  font-size: 14px;
  padding-top: 5px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 5;
}

.playlists-container .top-card .bg {
  width: 100%;
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 0;
  filter: blur(20px);
}

.playlists-container .top-card .bg-mask {
  width: 100%;
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
}

.playlists-container .tab-container {
  margin: 0px 20px;
}

.playlists-container .tab-container .tab-bar {
  margin-bottom: 10px;
  display: flex;
  justify-content: flex-end;
}

.playlists-container .tab-container .tab-bar .item {
  font-size: 14px;
  color: gray;
  margin-right: 10px;
  cursor: pointer;
}

.playlists-container .tab-container .tab-bar .item.active {
  color: $primary;
}
.recombox {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  :after {
    content: "";
    width: 180px;
  }
}
.recom-item {
  box-sizing: border-box;
  width: 20%;
  padding: 10px;
  .imgbox {
    width: 100%;
    position: relative;
    overflow: hidden;
    border-radius: 5px;
    img {
      width: 100%;
      object-fit: cover;
      border-radius: 5px;
    }
    .dsc {
      position: absolute;
      width: 100%;
      height: 30px;
      background-color: rgba(0, 0, 0, 0.5);
      top: 0px;
      left: 0px;
      transition: 0.5s;
      text-align: right;
      i {
        display: inline-block;
        width: 85%;
        color: rgb(255, 255, 255);
        font-size: 14px;
        line-height: 25px;
        font-style: normal;
        margin: 0px 10px;
      }
    }
  }
  .imgbox:hover {
    cursor: pointer;
  }
  .imgbox:hover .dsc {
    top: 0px;
  }
  p {
    margin: 0px;
    height: 30px;
    line-height: 30px;
    font-size: 13px;
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}
.pagebox {
  display: flex;
  width: 100%;
  height: 60px;
  justify-content: center;
  align-items: center;
}
.more {
  display: none;
}
.outter {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
}
.outter .inner {
  width: 100%;
  max-width: 1200px !important;
}

/deep/ .el-pagination.is-background .el-pager li:not(.disabled).active {
  background-color: $primary;
}
/deep/ .el-pagination.is-background .el-pager li:not(.disabled):hover {
  color: $primary;
}
</style>
